Skip to content

fix Can't remove samples link product downloadable #31895

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: 2.4-develop
Choose a base branch
from

Conversation

omaxmo
Copy link
Contributor

@omaxmo omaxmo commented Jan 29, 2021

Description (*)

When you create a product downloadable and create samples link or simples file then you can't remove the all sample it. This error in Magento 2.4.1. It works fine in Magento 2.4.0

Fixed Issues (if relevant)

  1. Fixes Can't remove samples link product downloadable. #31887

Manual testing scenarios (*)

  1. Go to adminpanel
  2. Go to downloadable product
  3. Remove all samples links
  4. Click save

Questions or comments

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds are green)

@m2-assistant
Copy link

m2-assistant bot commented Jan 29, 2021

Hi @omaxmo. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names. Allowed build names are:

  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE,
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests
  13. Semantic Version Checker

You can find more information about the builds here

ℹ️ Please run only needed test builds instead of all when developing. Please run all test builds before sending your PR for review.

For more details, please, review the Magento Contributor Guide documentation.

⚠️ According to the Magento Contribution requirements, all Pull Requests must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

🕙 You can find the schedule on the Magento Community Calendar page.

📞 The triage of Pull Requests happens in the queue order. If you want to speed up the delivery of your contribution, please join the Community Contributions Triage session to discuss the appropriate ticket.

🎥 You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel

✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

@m2-community-project m2-community-project bot added Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Severity: S2 Major restrictions or short-term circumventions are required until a fix is available. labels Jan 29, 2021
@omaxmo
Copy link
Contributor Author

omaxmo commented Jan 29, 2021

@magento run all tests

Copy link
Contributor

@gabrieldagama gabrieldagama left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @omaxmo, nice catch! Thanks for contributing. I believe now we need to update the unit test that is failing at the moment, and also, based on our definition of done, all contributions must be covered with automated tests. In this case the Unit test is not enough since it wasn't picking up the previous issue.

Please let me know if you need any help with it! Thanks!

@engcom-Hotel
Copy link
Contributor

@magento run Unit Tests

@engcom-Hotel
Copy link
Contributor

@magento run all tests

@omaxmo
Copy link
Contributor Author

omaxmo commented Feb 1, 2021

@magento run Integration Tests, Functional Tests EE, Functional Tests B2B

@engcom-Hotel
Copy link
Contributor

@magento run all tests

2 similar comments
@engcom-Hotel
Copy link
Contributor

@magento run all tests

@omaxmo
Copy link
Contributor Author

omaxmo commented Feb 2, 2021

@magento run all tests

@omaxmo
Copy link
Contributor Author

omaxmo commented Feb 3, 2021

@magento run Integration Tests

@omaxmo omaxmo requested a review from gabrieldagama February 3, 2021 05:55
@engcom-Hotel
Copy link
Contributor

@magento run Integration Tests

@engcom-Foxtrot engcom-Foxtrot added the Auto-Tests: Covered All changes in Pull Request is covered by auto-tests label Mar 5, 2021
Copy link
Contributor

@gabrieldagama gabrieldagama left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @engcom-Foxtrot, thanks for updating the PR

Can you check my comments below? Thanks!

@@ -326,10 +326,8 @@ public function testUpdateDownloadableProductData(): void
$response = $this->saveProduct($productData);

$this->assertArrayHasKey(ProductInterface::EXTENSION_ATTRIBUTES_KEY, $response);
$this->assertArrayHasKey(self::PRODUCT_SAMPLES, $response[ProductInterface::EXTENSION_ATTRIBUTES_KEY]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets double check if we need to remove these assertions

@@ -129,9 +129,6 @@ public function testExecuteNonDownloadable(): void
$this->entityMock->expects($this->once())
->method('getTypeId')
->willReturn(Type::TYPE_DOWNLOADABLE . 'some');
$this->entityMock->expects($this->once())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets double check if we need to remove these assertions

$this->assertArrayHasKey(self::PRODUCT_LINKS, $response[ProductInterface::EXTENSION_ATTRIBUTES_KEY]);

$this->assertCount(2, $response[ProductInterface::EXTENSION_ATTRIBUTES_KEY][self::PRODUCT_SAMPLES]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets double check if we need to remove these assertions

Copy link
Contributor

@gabrieldagama gabrieldagama left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @omaxmo, the proposed solution works, but it causes another problem on webapi interface.

With such fix, whenever a user updates a product via webapi its samples will be removed, this behavior doesn't happen outside the PR because the function updateSamples doesn't get called if the $samples is empty, but since that was removed, not it is getting called and ends up removing all samples. Can you check that?

Thanks!

@omaxmo
Copy link
Contributor Author

omaxmo commented Apr 10, 2021

@gabrieldagama I don't have any problems. Magento 2.4.2
curl --location --request PUT 'https://xxx/rest/all/V1/products/240-LV06' \ --header 'Authorization: Bearer xxx' \ --header 'Content-Type: application/json' \ --header 'Cookie: PHPSESSID=xxx' \ --data-raw '{ "product": { "name": "Test", "attribute_set_id": 14, "price": 100, "status": 1, "custom_attributes": [ { "attribute_code": "description", "value": "Test Description" }, { "attribute_code": "short_description", "value": "Test Short Description" } ] } }'

Response:

{
    "id": 49,
    "sku": "240-LV06",
    "name": "Test",
    "attribute_set_id": 14,
    "price": 100,
    "status": 1,
    "visibility": 4,
    "type_id": "downloadable",
    "created_at": "2021-03-03 10:03:10",
    "updated_at": "2021-04-10 12:36:15",
    "extension_attributes": {
        "website_ids": [
            1
        ],
        "category_links": [
            {
                "position": 0,
                "category_id": "9"
            },
            {
                "position": 0,
                "category_id": "10"
            }
        ],
        "stock_item": {
            "item_id": 49,
            "product_id": 49,
            "stock_id": 1,
            "qty": null,
            "is_in_stock": true,
            "is_qty_decimal": false,
            "show_default_notification_message": false,
            "use_config_min_qty": true,
            "min_qty": 0,
            "use_config_min_sale_qty": 1,
            "min_sale_qty": 1,
            "use_config_max_sale_qty": true,
            "max_sale_qty": 10000,
            "use_config_backorders": true,
            "backorders": 0,
            "use_config_notify_stock_qty": true,
            "notify_stock_qty": 1,
            "use_config_qty_increments": true,
            "qty_increments": 0,
            "use_config_enable_qty_inc": true,
            "enable_qty_increments": false,
            "use_config_manage_stock": false,
            "manage_stock": false,
            "low_stock_date": "2021-04-10 12:36:15",
            "is_decimal_divided": false,
            "stock_status_changed_auto": 0
        },
        "downloadable_product_links": [
            {
                "id": 3,
                "title": "Yoga Adventure",
                "sort_order": 1,
                "is_shareable": 2,
                "price": 22,
                "number_of_downloads": 0,
                "link_type": "file",
                "link_file": "/l/u/luma_background_-_model_against_fence_4_sec_.mp4",
                "sample_type": null
            }
        ],
        "downloadable_product_samples": [
            {
                "id": 7,
                "title": "Trailer #1",
                "sort_order": 1,
                "sample_type": "file",
                "sample_file": "/l/u/luma_background_-_model_against_fence_4_sec_.mp4"
            },
            {
                "id": 8,
                "title": "Trailer #2",
                "sort_order": 1,
                "sample_type": "file",
                "sample_file": "/l/u/luma_background_-_model_against_fence_4_sec_.mp4"
            },
            {
                "id": 9,
                "title": "Trailer #3",
                "sort_order": 1,
                "sample_type": "file",
                "sample_file": "/l/u/luma_background_-_model_against_fence_4_sec_.mp4"
            }
        ]
    },
    "product_links": [],
    "options": [],
    "media_gallery_entries": [
        {
            "id": 55,
            "media_type": "image",
            "label": "Image",
            "position": 1,
            "disabled": false,
            "types": [
                "image",
                "small_image",
                "thumbnail"
            ],
            "file": "/l/t/lt03.jpg"
        }
    ],
    "tier_prices": [],
    "custom_attributes": [
        {
            "attribute_code": "image",
            "value": "/l/t/lt03.jpg"
        },
        {
            "attribute_code": "small_image",
            "value": "/l/t/lt03.jpg"
        },
        {
            "attribute_code": "thumbnail",
            "value": "/l/t/lt03.jpg"
        },
        {
            "attribute_code": "options_container",
            "value": "container2"
        },
        {
            "attribute_code": "msrp_display_actual_price_type",
            "value": "0"
        },
        {
            "attribute_code": "url_key",
            "value": "yoga-adventure"
        },
        {
            "attribute_code": "required_options",
            "value": "0"
        },
        {
            "attribute_code": "has_options",
            "value": "0"
        },
        {
            "attribute_code": "image_label",
            "value": "Image"
        },
        {
            "attribute_code": "small_image_label",
            "value": "Image"
        },
        {
            "attribute_code": "thumbnail_label",
            "value": "Image"
        },
        {
            "attribute_code": "tax_class_id",
            "value": "2"
        },
        {
            "attribute_code": "category_ids",
            "value": [
                "9",
                "10"
            ]
        },
        {
            "attribute_code": "short_description",
            "value": "Test Short Description"
        },
        {
            "attribute_code": "description",
            "value": "Test Description"
        },
        {
            "attribute_code": "links_purchased_separately",
            "value": "0"
        },
        {
            "attribute_code": "samples_title",
            "value": "Trailers"
        },
        {
            "attribute_code": "links_title",
            "value": "Downloads"
        },
        {
            "attribute_code": "format",
            "value": "102"
        },
        {
            "attribute_code": "activity",
            "value": "8,16"
        }
    ]
}

All samples present after the update.

@omaxmo omaxmo requested a review from gabrieldagama April 10, 2021 12:48
@gabrieldagama
Copy link
Contributor

Hi @omaxmo, I believe you should test with your PR, the problem is introduced with this change.

Thanks!

@omaxmo
Copy link
Contributor Author

omaxmo commented Apr 12, 2021

Hi @gabrieldagama , Yes, I know. But still don't have a problem. Do I need to update some specific attributes?

curl --location --request PUT 'https://xxx/rest/all/V1/products/sampletest' \
--header 'Authorization: Bearer x3ux9f2njtoi3d1s10t9wpe18r5igiiz' \
--header 'Content-Type: application/json' \
--header 'Cookie: PHPSESSID=7hr3vsvn13l13kvaqq33kgi4el' \
--data-raw '{
  "product": {
    "name": "Test1111",
    "attribute_set_id": 4,
    "price": 100,
    "status": 1,
    "custom_attributes": [
      {
        "attribute_code": "description",
        "value": "TestDescription"
      },
      {
        "attribute_code": "short_description",
        "value": "Test Short Description"
      }
    ]
  }
}
{
    "id": 1,
    "sku": "sampletest",
    "name": "Test1111",
    "attribute_set_id": 4,
    "price": 100,
    "status": 1,
    "visibility": 4,
    "type_id": "downloadable",
    "created_at": "2021-04-12 13:00:57",
    "updated_at": "2021-04-12 14:32:01",
    "extension_attributes": {
        "website_ids": [
            1
        ],
        "category_links": [
            {
                "position": 0,
                "category_id": "2"
            }
        ],
        "stock_item": {
            "item_id": 1,
            "product_id": 1,
            "stock_id": 1,
            "qty": 0,
            "is_in_stock": false,
            "is_qty_decimal": false,
            "show_default_notification_message": false,
            "use_config_min_qty": true,
            "min_qty": 0,
            "use_config_min_sale_qty": 1,
            "min_sale_qty": 1,
            "use_config_max_sale_qty": true,
            "max_sale_qty": 10000,
            "use_config_backorders": true,
            "backorders": 0,
            "use_config_notify_stock_qty": true,
            "notify_stock_qty": 1,
            "use_config_qty_increments": true,
            "qty_increments": 0,
            "use_config_enable_qty_inc": true,
            "enable_qty_increments": false,
            "use_config_manage_stock": true,
            "manage_stock": true,
            "low_stock_date": "2021-04-12 14:32:02",
            "is_decimal_divided": false,
            "stock_status_changed_auto": 1
        },
        "downloadable_product_links": [
            {
                "id": 1,
                "title": "234234",
                "sort_order": 1,
                "is_shareable": 1,
                "price": 0,
                "number_of_downloads": 0,
                "link_type": "file",
                "link_file": "/s/a/samplevideo_1280x720_1mb.mp4",
                "sample_type": "file",
                "sample_file": "/s/a/samplevideo_1280x720_1mb.mp4"
            }
        ],
        "downloadable_product_samples": [
            {
                "id": 3,
                "title": "wefwef",
                "sort_order": 1,
                "sample_type": "file",
                "sample_file": "/s/a/samplevideo_1280x720_1mb.mp4"
            },
            {
                "id": 4,
                "title": "232332",
                "sort_order": 2,
                "sample_type": "file",
                "sample_file": "/s/a/samplevideo_1280x720_1mb_1.mp4"
            }
        ]
    },
    "product_links": [],
    "options": [],
    "media_gallery_entries": [],
    "tier_prices": [],
    "custom_attributes": [
        {
            "attribute_code": "options_container",
            "value": "container2"
        },
        {
            "attribute_code": "url_key",
            "value": "sample-test"
        },
        {
            "attribute_code": "gift_message_available",
            "value": "2"
        },
        {
            "attribute_code": "msrp_display_actual_price_type",
            "value": "0"
        },
        {
            "attribute_code": "required_options",
            "value": "0"
        },
        {
            "attribute_code": "has_options",
            "value": "0"
        },
        {
            "attribute_code": "meta_title",
            "value": "sample test"
        },
        {
            "attribute_code": "meta_keyword",
            "value": "sample test"
        },
        {
            "attribute_code": "meta_description",
            "value": "sample test "
        },
        {
            "attribute_code": "tax_class_id",
            "value": "2"
        },
        {
            "attribute_code": "category_ids",
            "value": [
                "2"
            ]
        },
        {
            "attribute_code": "short_description",
            "value": "Test Short Description"
        },
        {
            "attribute_code": "description",
            "value": "TestDescription"
        },
        {
            "attribute_code": "links_purchased_separately",
            "value": "0"
        },
        {
            "attribute_code": "samples_title",
            "value": "Samples"
        },
        {
            "attribute_code": "links_title",
            "value": "Links"
        }
    ]
}

@omaxmo
Copy link
Contributor Author

omaxmo commented Apr 12, 2021

@gabrieldagama It's not working after merge. I will check

@m2-community-project m2-community-project bot added the Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround. label Oct 1, 2021
@engcom-Charlie engcom-Charlie self-assigned this Jun 16, 2022
@engcom-Charlie
Copy link
Contributor

engcom-Charlie commented Jun 16, 2022

Hi @omaxmo,

Thank you for your contribution!

Do you get any opportunity to look on above comment.

Thank you!

@engcom-Charlie
Copy link
Contributor

@magento run all tests

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@engcom-Charlie
Copy link
Contributor

@magento run Functional Tests B2B, Functional Tests CE, Functional Tests EE

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@engcom-Charlie
Copy link
Contributor

@magento run Functional Tests CE

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@engcom-Charlie
Copy link
Contributor

As per this comment, tried to update the product "test" by webapi

image

Response::

{
"id": 2049,
"sku": "test",
"name": "test",
"attribute_set_id": 4,
"price": 110,
"status": 1,
"visibility": 4,
"type_id": "downloadable",
"created_at": "2022-06-21 10:00:12",
"updated_at": "2022-06-22 11:12:33",
"extension_attributes": {
"website_ids": [
1
],
"category_links": [
{
"position": 0,
"category_id": "42"
}
],
"stock_item": {
"item_id": 2049,
"product_id": 2049,
"stock_id": 1,
"qty": 0,
"is_in_stock": false,
"is_qty_decimal": false,
"show_default_notification_message": false,
"use_config_min_qty": true,
"min_qty": 0,
"use_config_min_sale_qty": 1,
"min_sale_qty": 1,
"use_config_max_sale_qty": true,
"max_sale_qty": 10000,
"use_config_backorders": true,
"backorders": 0,
"use_config_notify_stock_qty": true,
"notify_stock_qty": 1,
"use_config_qty_increments": true,
"qty_increments": 0,
"use_config_enable_qty_inc": true,
"enable_qty_increments": false,
"use_config_manage_stock": true,
"manage_stock": true,
"low_stock_date": "2022-06-22 11:12:33",
"is_decimal_divided": false,
"stock_status_changed_auto": 1
},
"downloadable_product_links": [
{
"id": 9,
"title": "links1",
"sort_order": 1,
"is_shareable": 1,
"price": 110,
"number_of_downloads": 0,
"link_type": "url",
"link_url": "http://magento-31895.local/",
"sample_type": "url",
"sample_url": "http://magento-31895.local/"
},
{
"id": 10,
"title": "link2",
"sort_order": 2,
"is_shareable": 1,
"price": 110,
"number_of_downloads": 0,
"link_type": "url",
"link_url": "http://magento-31895.local/",
"sample_type": "url",
"sample_url": "http://magento-31895.local/"
}
],
"downloadable_product_samples": [
{
"id": 23,
"title": "samples 2",
"sort_order": 1,
"sample_type": "url",
"sample_url": "http://magento-31895.local/"
},
{
"id": 24,
"title": "samples3",
"sort_order": 2,
"sample_type": "url",
"sample_url": "http://magento-31895.local/"
}
]
},
"product_links": [],
"options": [],
"media_gallery_entries": [],
"tier_prices": [],
"custom_attributes": [
{
"attribute_code": "options_container",
"value": "container2"
},
{
"attribute_code": "url_key",
"value": "test"
},
{
"attribute_code": "gift_message_available",
"value": "2"
},
{
"attribute_code": "msrp_display_actual_price_type",
"value": "0"
},
{
"attribute_code": "required_options",
"value": "0"
},
{
"attribute_code": "has_options",
"value": "0"
},
{
"attribute_code": "meta_title",
"value": "test"
},
{
"attribute_code": "meta_keyword",
"value": "test"
},
{
"attribute_code": "meta_description",
"value": "test "
},
{
"attribute_code": "tax_class_id",
"value": "2"
},
{
"attribute_code": "category_ids",
"value": [
"42"
]
},
{
"attribute_code": "short_description",
"value": "Test Short Description"
},
{
"attribute_code": "description",
"value": "TestDescription"
},
{
"attribute_code": "links_purchased_separately",
"value": "1"
},
{
"attribute_code": "samples_title",
"value": "Samples"
},
{
"attribute_code": "links_title",
"value": "Links"
}
]
}

Observed that after updating the product via web API, the samples are not getting removed. Tested after latest Magento code.

Also all the test cases are getting passed and the build is green, hence asking for review.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auto-Tests: Covered All changes in Pull Request is covered by auto-tests Component: Downloadable Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: pending review Release Line: 2.4 Severity: S2 Major restrictions or short-term circumventions are required until a fix is available. Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't remove samples link product downloadable.
6 participants